package com.yu8home.mq.rabbit.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 主题交换机：通过模式匹配路由键来分发消息
 */
@Configuration
public class TopicConfig {
    String b = "yu8home.topic.bbbb";
    String c = "yu8home.topic.cccc";

    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange("yu8home.topic");
    }

    @Bean
    public Queue topicQueueB() {
        return new Queue(b);
    }

    @Bean
    public Queue topicQueueC() {
        return new Queue(c);
    }


    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    @Bean
    Binding bindingB(Queue topicQueueB, TopicExchange topicExchange) {
        return BindingBuilder
                .bind(topicQueueB)
                .to(topicExchange)
                .with("yu8home.topic.bbbb");
    }

    @Bean
    Binding bindingC(Queue topicQueueC, TopicExchange topicExchange) {
        return BindingBuilder
                .bind(topicQueueC)
                .to(topicExchange)
                .with("yu8home.topic.#");// *一个词、#零个或多个词
    }

}
